package com.gc.controller;

import com.gc.common.constants.SysConstants;
import com.gc.dto.DeviceUseDTO;
import com.gc.pojo.SysDeviceUse;
import com.gc.pojo.SysUser;
import com.gc.services.DeviceService;
import com.gc.services.DeviceUseService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("device-use")
public class DeviceUseController {

    @Autowired
    private DeviceUseService deviceUseService;
    @RequestMapping("record-view")
    @ResponseBody
    public ModelAndView recordView(){
        ModelAndView mav = new ModelAndView("device/use-record");
        return mav;
    }

    @RequestMapping("getAll")
    @ResponseBody
    public List<DeviceUseDTO> getMyList(){
        Subject subject = SecurityUtils.getSubject();
        SysUser curUser = (SysUser) subject.getPrincipal();
        if(subject.hasRole(SysConstants.SYS_ROLE5)){
           return  deviceUseService.getListByUid(curUser.getUserId());
        }
        return deviceUseService.getAll();
    }
}
